package com.swjd.controller;

import com.swjd.pojo.Goods;
import com.swjd.service.impl.GoodsServiceImpl;
import com.swjd.util.BecomeJson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created by hxl on 2019/5/31  9:11
 */
@Controller
@RequestMapping(value = "action/", method = RequestMethod.POST)
public class GoodsController {
    @Autowired
    private GoodsServiceImpl goodsService;

    @ResponseBody
    @RequestMapping("queryGoods")//根据用户输入的内容进行模糊查询
    public List<Goods> query(@RequestParam("input") String input) {//根据用户输入的内容进行模糊查询
        return goodsService.fuzzyQuery(input);
    }


    @ResponseBody
    @RequestMapping("selectUserByGoods")//用户查询发布的商品信息
    public List<Goods> selectUserByGoods(@RequestParam("username") String username) {
        return goodsService.selectUserByGoods(username);
    }

    @ResponseBody
    @RequestMapping("selectIfSell")//查询商品是否已经售出
    public List<Goods> selectIfSell() {
        return goodsService.selectIfSell();
    }

    @ResponseBody
    @RequestMapping("insertGoods")
    public String insert(@RequestBody Goods goods) {//添加商品信息
        System.out.println(goods.toString());
        return BecomeJson.isOk(goodsService.insertGoods(goods));
    }

    @ResponseBody
    @RequestMapping("deleteGoods")
    public String delete(@RequestParam("goodsID") Integer goodsID) {//删除商品信息
        return BecomeJson.isOk(goodsService.deleteByID(goodsID));
    }

    @ResponseBody
    @RequestMapping("updateGoods")
    public String update(@RequestBody Goods goods) {//修改商品信息
        System.out.println(goods.toString());
        return BecomeJson.isOk(goodsService.updateByID(goods));
    }

    @ResponseBody
    @RequestMapping("updateByStatus")
    public String updateByStatus() {//修改商品状态
        return BecomeJson.isOk(goodsService.updateByStatus());
    }
}
